import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
const routes = [
  {
    path: '/',
  redirect:"/login"
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login.vue')
  },
  {
    path: '/jichu',
    name: 'jichu',
    component: () => import('../views/jichu/shangpin.vue'),
    meta: { title: "商品管理" },
  },
  {
    path: '/dingdan',
    name: 'dingdan',
    component: () => import('../views/dingdan/jiaoyi.vue'),
    meta: { title: "交易订单" },
  },
  {
    path: '/xitong',
    name: 'xitong',
    component: () => import('../views/xitong/yonghu.vue'),
    meta: { title: "用户管理" },
  },
  {
    path: '/zhifu',
    name: 'zhifu',
    component: () => import('../views/zhifu/zhifu.vue'),
    meta: { title: "支付配置信息" },
  }
]
const router = new VueRouter({
    routes,
});
// 全局路由守卫
router.beforeEach((to, from, next) => {
    if (localStorage.getItem("token")) {
        next();
    } else {
        if (to.path == "/login") {
            next();
        } else {
            next("/login");
        }
    }
});

export default router;